<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../css/common.css" />
		<link rel="stylesheet" href="../css/mui.picker.min.css" />
	</head>
	<style type="text/css">
		.mui-bar-nav .mui-pull-right {
			display: inline-block;
			padding: 0;
			margin: 0;
			height: 44px;
			line-height: 44px;
			font-size: 1.05rem;
		}
	</style>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">人员列表</h1>
			<a href="addPerson.html" class="mui-icon  mui-pull-right">新增</a>
		</header>
		<div class="mui-content">
			<div class="search-li">
		    	<div class="search-box">
				    <input type="search" id="person_serch_input" placeholder="请输入人员信息">
					<button type="button" id="serchPerson">查询</button>
		    	</div>
			</div>
			<div class="personHouseAddress" style="border-top: 1px solid #dfdfdf;border-bottom: 1px solid #dfdfdf;">
					<p id="Address"></p>
			</div>
			<div class="person-list">
				<ul id="personUl">

				</ul>
			</div>
		</div>
		<script src="../js/jquery.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<script src="../js/md5.js"></script>
		<script>
		if(localStorage.getItem('buildingInfo')){
			var buildingInfo = JSON.parse(localStorage.getItem('buildingInfo'));
			document.getElementById("Address").innerHTML = buildingInfo.buildingName;
		}
		//获取人员列表	
		function initPage_person(houseId,keyword){
			var houseId = houseId ;
			var keyword = keyword;
			var mobile = localStorage.getItem('mobile');//本地取到电话号码
			var timestamp = formatDateTime();//年月日时分秒
			var key = 'udacs!@#';//固定的key值
			var token = mobile + timestamp + key;//token的拼接
			var md5 = hex_md5(token);//token的ma5加密
			$.ajax(httpUrl+'get_renter_list',{
				data:JSON.stringify({
					"auth":{
						"mobile":mobile,
						"token":md5,
						"imei":"imei",
						"imsi":"imsi",
						"timestamp" :timestamp
					},
			   		"api_ver":"1",
					"req":{
						"mobile":mobile ,
						"id":houseId,//楼栋或者房屋的id
						"page":"1",
						'key':keyword,
						"filter_type":'1',//1楼栋，0位房屋
						"type":"1"
					}
				}),
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				contentType: "text/plain; charset=utf-8",					
				success:function(data){
					var resp =JSON.stringify(data.resp)
					var res = JSON.parse(resp);
					//给隐藏域赋值，用于传给父级请求数据页面的个人信息
					var personUl = document.getElementById('personUl')
					mui.each(res, function(ind,item) {
						personUl.insertAdjacentHTML('beforeEnd','<li class="mui-clearfix" ><div class="personInfo" data-mobile="'+item.user_mobile+'" data-nation="'+item.user_nation+'" data-birth="'+item.user_bir+'"data-sex="'+item.sex+'"><p class="personINfoName">'+item.user_name+'</p><p>'+item.id_card+'</p></div></li>')
					});
				},
				error:function(xhr,type,errorThrown){
					mui.toast('网络异常或者服务器出错：'+type,{duration:'2000',type:'div'});
				}
				
			})
		}	
		var houseId = getUrlMobile('houseId');
		initPage_person(houseId,'');//默认空值
		//模糊查询
		document.getElementById("serchPerson").addEventListener('tap',function(){
			var person_serch_input = document.getElementById("person_serch_input").value;
			initPage_person(houseId,person_serch_input);
		})
		//点击列表，获取个人信息，存储本地，返回授权页面
		mui('#personUl').on('tap','li .personInfo',function(){
			var personInfo = {
				personName : this.getElementsByTagName('p')[0].innerText,
				personidNum : this.getElementsByTagName('p')[1].innerText,
				person_user_bir : this.getAttribute('data-birth'),
				person_user_nation :this.getAttribute('data-nation'),
				person_user_mobile : this.getAttribute('data-mobile'),
				person_sex : this.getAttribute('data-sex'),
			}
			localStorage.setItem('personInfo',JSON.stringify(personInfo))
			var mobile = localStorage.getItem('mobile');
			location.href = 'authorization.html?hasLocalStorage=true&&mobile='+mobile;
		})
		</script>
	</body>

</html>